/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.util;

/**
 *
 * @author Santos
 */
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPasswordField;

public class ConvertPasswordToMD5 {

    public static String convertPasswordToMD5(JPasswordField jPassowrdField) {
        try {
            String password = jPassowrdField.getText();
            MessageDigest md = MessageDigest.getInstance("MD5");
            BigInteger hash = new BigInteger(1, md.digest(password.getBytes()));
            return String.format("%32x", hash);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(ConvertPasswordToMD5.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
